<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            position: relative;
            width: 50px;
            height: 50px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <div>移动</div>
    <script>
        var div = document.querySelector('div');
        var time = setInterval(function() {
            if (div.offsetLeft == 300) {
                clearInterval('time');
            }

            div.style.left = div.offsetLeft + 1 + 'px';
        }, 30)
    </script>
</body>

</html>